package com.fjsh.exception;

import com.fjsh.enums.HttpStatus;
import com.fjsh.vo.ApiResult;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 全局动态数据源异常处理
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    //region 拦截运行时异常
    /**
     * 拦截运行时异常
     */
    @ExceptionHandler(RuntimeException.class)
    public ApiResult runtimeException(Exception exception) {
        return ApiResult.error(500, exception.getMessage());
    }
    //endregion

    //region 拦截自定义业务异常
    /**
     * 拦截自定义业务异常
     */
    @ExceptionHandler(BusinessException.class)
    public ApiResult businessException(Exception exception) {
        return ApiResult.error(HttpStatus.EXCEPTION.getCode(), exception.getMessage());
    }
    //endregion
}
